package com.linkhub.oms.admin.modules.logistic.freighttemplate.domain.param;

import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.linkhub.oms.admin.modules.logistic.freighttemplate.domain.vo.FreightTemplateDetailVO;
import com.linkhub.oms.admin.modules.user.domain.param.BaseUserParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * <p>
 * 运费模板新增实体
 * </p>
 *
 * @author Frank
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "LogisticFreightTemplateAddParam", description = "LogisticFreightTemplateAddParam")
public class LogisticFreightTemplateAddParam extends BaseUserParam implements Serializable {

    @ApiModelProperty(value = "模板名称")
    @NotBlank(message = "{freight.template.empty}")
    private String templateName;

    @ApiModelProperty(value = "模板生效日期")
    private String effectiveDate;

    @ApiModelProperty(value = "模板失效日期")
    private String expirationDate;

    @ApiModelProperty(value = "渠道编码")
    @NotBlank(message = "{freight.template.channel.empty}")
    private String channelCode;

    @ApiModelProperty(value = "渠道中文名称")
    private String channelCName;

    @ApiModelProperty(value = "渠道英文名称")
    private String channelEName;

    @ApiModelProperty(value = "国家编码")
    @NotBlank(message = "{freight.template.country.empty}")
    private String countryCode;

    @ApiModelProperty(value = "国家分区")
    private String countryPartition;

    @ApiModelProperty(value = "计泡系数")
    private Integer bubbleCoefficient;

    @ApiModelProperty(value = "最低计费重量")
    private BigDecimal minimumChargeableWeight;

    @ApiModelProperty(value = "实际费用币种")
    private String actualFeeCurrencyType;

    @ApiModelProperty(value = "进位方式 1：默认（不进位） 2：向上取整")
    private Integer carryMethod;

    @ApiModelProperty(value = "重量范围")
    private List<FreightTemplateDetailVO> templateDetails;


    @JsonIgnore
    public LocalDateTime getEffectiveDateConvert() {
        if (StringUtils.isBlank(effectiveDate)) {
            return null;
        }
        return LocalDateTime.parse(effectiveDate, DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
    }

    @JsonIgnore
    public LocalDateTime getExpirationDateConvert() {
        if (StringUtils.isBlank(expirationDate)) {
            return null;
        }
        return LocalDateTime.parse(expirationDate, DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
    }
}
